package com.zhiyou.servlet;

import com.zhiyou.dao.HouseDao;
import com.zhiyou.model.House;
import com.zhiyou.service.HouseService;
import com.zhiyou.service.impl.HouseServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class HouseAddServlet extends HttpServlet {
    private HouseService hS=new HouseServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        req.setCharacterEncoding("utf-8");
//        resp.setContentType("text/html;charset=utf-8");
        System.out.println("添加成功");
        String haddress = req.getParameter("haddress");
        String hfloor = req.getParameter("hfloor");
        int hroomNum = Integer.parseInt(req.getParameter("hroomNum"));
        String harea = req.getParameter("harea");
        String hdir = req.getParameter("hdir");
        int hdeco = Integer.parseInt(req.getParameter("hdeco"));
        int hair = Integer.parseInt(req.getParameter("hair"));
        double hprice =Double.parseDouble(req.getParameter("hprice"));
        int hrentStatus = Integer.parseInt(req.getParameter("hrentStatus"));
        String himage = req.getParameter("himage");
        String haddTime = req.getParameter("haddTime");
        String hupdateTime = req.getParameter("hupdateTime");
        if(haddress!=""&&hfloor!=""&&hroomNum!=0&&harea!=""&&hdir!=""&&hdeco!=0&&hair!=0&&hprice!=0&&hrentStatus!=0&&himage!=""&&haddTime!=""&&hupdateTime!=""){
            hS.addNew(haddress,hfloor,hroomNum,harea,hdir,hdeco,hair,hprice,hrentStatus,himage,haddTime,hupdateTime);
            //new HouseDao().addNew(haddress,hfloor,hroomNum,harea,hdir,hdeco,hair,hprice,hrentStatus,himage,haddTime,hupdateTime);
            //List<House> houses = hS.getHouse(1,3);
            //req.getSession().setAttribute("houses",houses);
            resp.sendRedirect(req.getContextPath()+"/user/house?pageNo="+req.getParameter("pageNo"));
        }else{
            req.setAttribute("err","注册失败,请将信息填写完整");
            resp.sendRedirect(req.getContextPath()+"/view/flats/add.jsp");
        }

    }
}
